﻿using PermissionManager.Model;
using PermissionsManager.BLL;
using System.Collections.Generic;
using System.Linq;

namespace PermissionManager.BLL
{
    public class ModuleService : BaseService<Module>
    {
        public List<Role> GetRoleByModule(int moduleId) {
            using (var db=new PermissionManagerEntities())
            {
                List<Role> roles = new List<Role>();
                var result = db.ModuleRole.Where(a=>a.ModuleId==moduleId);
                foreach (var item in result)
                {
                    roles.Add(new Role()
                    {
                        Id = item.RoleId??0,
                        Name = db.Role.FirstOrDefault(a=>a.Id==item.RoleId).Name
                    });
                }
                return roles;
            }
        }
    }
}
